package com.gec;

import com.gec.model.User;
import com.gec.respository.UserRepository;
import org.bson.types.ObjectId;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@SpringBootTest
public class Demo {

    @Autowired
    UserRepository userRepository;

    @Test
    public void  save(){
        User user = new User();
        user.setAge(12);
        user.setName("Tom");
        user.setCreateDate(new Date());
        user.setEmail("223224424");
        userRepository.save(user);
    }

    @Test
    public void  find(){
        List<User> all = userRepository.findAll();
        all.stream().forEach(item-> System.out.println(item));
    }
    @Test
    public void  findByName(){
        Optional<User> user = userRepository.findById(new ObjectId("6731a174acc4c277b352edae"));
        User user1 = user.get();
        System.out.println(user1);
    }
}
